home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / pccts.zip / SUPPORT.C < prev    next >
C/C++ Source or Header  |  1992-12-08  |  2KB  |  128 lines

  1. #include <stdio.h>
  2. #include "dlg.h"
  3. #ifdef MEMCHK
  4. #include "trax.h"
  5. #else
  6. extern char *malloc();
  7. extern char *calloc();
  8. #endif
  9.  
  10. int    err_found = 0;            /* indicates whether problem found */
  11.  
  12. internal_error(s,file,line)
  13. char *s,*file;
  14. int line;
  15. {
  16.     fprintf(stderr,s,file,line);
  17.     exit(1);
  18. }
  19.  
  20. char *dlg_malloc(bytes,file,line)
  21. int bytes;
  22. char *file;
  23. int line;
  24. {
  25.     char *t;
  26.  
  27.     t = (char *) malloc(bytes);
  28.     if (!t){
  29.         /* error */
  30.         internal_error("%s(%d): unable to allocate memory\n",
  31.             file,line);
  32.     }
  33.     return t;
  34. }
  35.  
  36.  
  37. char *dlg_calloc(n,bytes,file,line)
  38. int n,bytes;
  39. char *file;
  40. int line;
  41. {
  42.     char *t;
  43.  
  44.     t = (char *) calloc(n,bytes);
  45.     if (!t){
  46.         /* error */
  47.         internal_error("%s(%d): unable to allocate memory\n",
  48.             file,line);
  49.     }
  50.     return t;
  51. }
  52.  
  53.  
  54. FILE *read_stream(name)
  55. char *name;
  56. {
  57.     FILE *f;
  58.  
  59.     if (name){
  60.         if (name[0] == '-') {
  61.             fprintf(stderr, "dlg: invalid option: '%s'\n", name);
  62.             f = NULL;
  63.         }else{
  64.             f = fopen(name, "r");
  65.             if (f == NULL){
  66.                 /* couldn't open file */
  67.                 fprintf(stderr,
  68.                     "dlg: Warning: Can't read file %s.\n",
  69.                     name);
  70.             }
  71.         }
  72.     }else{
  73.         /* open stdin if nothing there */
  74.         f = stdin;
  75.     }
  76.     return f;
  77. }
  78.  
  79. FILE *write_stream(name)
  80. char *name;
  81. {
  82.     FILE *f;
  83.  
  84.     if (name){
  85.         if (name[0] == '-') {
  86.             fprintf(stderr, "dlg: invalid option: '%s'\n", name);
  87.             f = NULL;
  88.         }else{
  89.             f = fopen(name, "w");
  90.             if (f == NULL){
  91.                 /* couldn't open file */
  92.                 fprintf(stderr,
  93.                     "dlg: Warning: Can't write to file %s.\n",
  94.                     name);
  95.             }
  96.         }
  97.     }else{
  98.         /* open stdin if nothing there */
  99.         f = stdout;
  100.     }
  101.     return f;
  102. }
  103.  
  104.  
  105. void fatal(message,line_no)
  106. char *message;
  107. int line_no;
  108. {
  109.     fprintf(stderr,"Fatal : %s, line : %d\n",message,line_no);
  110.     exit(2);
  111. }
  112.  
  113. void error(message,line_no)
  114. char *message;
  115. int line_no;
  116. {
  117.     fprintf(stderr,"\"%s\", line %d: %s\n",
  118.         (file_str[0] ? file_str[0] : "stdin"), line_no, message);
  119.     err_found = 1;
  120. }
  121.  
  122. void warning(message,line_no)
  123. char *message;
  124. int line_no;
  125. {
  126.     fprintf(stderr,"Warning : %s, line : %d\n",message,line_no);
  127. }
  128.